package br.com.aquinoevasconcelos.servlets.arquivo;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.com.aquinoevasconcelos.fachada.Fachada;
import br.com.aquinoevasconcelos.user.UsuarioCliente;

/**
 * Servlet implementation class ListaArquivoCliente
 */
@WebServlet("/ListaArquivoCliente")
public class ListaArquivoCliente extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
    public ListaArquivoCliente() {
        super();
    }

    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	
    	Fachada fachada = Fachada.getInstancia();
    	try {
    		UsuarioCliente cliente = new UsuarioCliente();
        	HttpSession sessaoCliente = request.getSession();
        	cliente = (UsuarioCliente) sessaoCliente.getAttribute("sessaoCliente");

    		request.setAttribute("listaArquivos", fachada.listaArquivoCliente(cliente.getId()));
    		
    		RequestDispatcher rd = request.getRequestDispatcher("/painel_usuario/listar_arquivos.jsp");
    		
			rd.forward(request, response);
		} catch (Exception e) {
			
			RequestDispatcher rd = request.getRequestDispatcher("pagina_erro/erro.jsp");
			rd.forward(request, response);
		}
    	
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

}
